home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 45
/
Amiga Format CD45 (1999-09)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-11].iso
/
-serious-
/
wb
/
wreplaceicon
/
wreplaceicon.e
< prev
next >
Wrap
Text File
|
1999-08-16
|
11KB
|
335 lines
-> WReplaceIcon V2.0 by Jilles Tjoelker 1999-07-15
-> Requires V41 BGUI modules, though V40 library should work.
-> 'libraries/bgui_macros' is an old module, so bgui.library V40
-> may work. If you don't have it, you may substitute 'libraries/bguim'
-> but it will not work 100% under V40.
-> TAB=2
->
-> New in V2.0:
->
-> * About button replaced by About option in menu.
-> * Options to copy or not image, type & default tool and tool types.
-> * Sizing gadget removed as it does not have any use.
-> * Reading of tool types added.
-> * File requester to select icons added.
->
-> Tool types (read from icon whether started from WB or CLI):
->
-> EQUALWIDTH: make the two areas the same size (yes/no)
-> MAXWIDTH,MAXHEIGHT: maximum size of images shown in the source box
-> COPYIMAGE,COPYTYPE,COPYTOOLTYPES: same options as in the menu (yes/no)
-> DEFDRAWER: default drawer for file requester (default: ENV:Sys)
OPT PREPROCESS,OSVERSION=37
MODULE 'bgui','libraries/bgui','libraries/bguic','libraries/bgui_macros',
'tools/boopsi','utility/tagitem','intuition/screens',
'intuition/gadgetclass','intuition/classusr','intuition/intuition',
'intuition/classes','workbench/workbench','icon',
'workbench/startup','libraries/gadtools','libraries/asl'
ENUM ID_NULL,ID_SRC,ID_ABOUT,ID_SELECT,ID_QUIT,ID_CIMAGE,ID_CTYPE,ID_CTTYPES
SET CP_IMAGE,CP_TYPE,CP_TTYPES
ENUM ERR_NONE,ERR_LIB,ERR_GUI,ERR_WIN
RAISE ERR_LIB IF OpenLibrary()=NIL
DEF wd_obj=NIL,sig,done,wnd,filereq=NIL
DEF doeqw=FALSE,maxw=100,maxh=60,copy=CP_IMAGE,defdrawer[256]:STRING
DEF g_Src,g_Dest
DEF diskobj_src=NIL:PTR TO diskobject,
diskobj_dst=NIL:PTR TO diskobject
PROC bguireq(title,text,gadgets,args=NIL)
DEF rq:bguiRequest
rq.flags:=BREQF_AUTO_ASPECT OR BREQF_LOCKWINDOW OR
(IF InStr(gadgets,'*')<>-1 THEN BREQF_FAST_KEYS ELSE 0)
rq.title:=title
rq.gadgetFormat:=gadgets
rq.textFormat:=text
rq.reqPos:=POS_CENTERMOUSE
rq.textAttr:=NIL
rq.underscore:="_"
rq.reserved0:=0
rq.screen:=NIL -> NOP
rq.reserved1:=0
ENDPROC BgUI_RequestA(wnd,rq,args)
INT 0
verstag:
CHAR '$VER: WReplaceIcon 2.0 (15.7.99)',0
PROC main() HANDLE
DEF amsg:PTR TO appmessage,wa:PTR TO wbarg,cd
DEF name[256]:STRING
DEF rc,i
DEF oldgadget:gadget,olddeft,oldtt:PTR TO LONG
StrCopy(defdrawer,'ENV:Sys')
iconbase:=OpenLibrary('icon.library',37)
gettooltypes(name)
bguibase:=OpenLibrary('bgui.library',40) -> WM_WHICHOBJECT requires V40
wd_obj:=WindowObject,
WINDOW_Title,'WReplaceIcon by JT',
WINDOW_AutoAspect,TRUE,
WINDOW_Position,POS_CENTERMOUSE,
WINDOW_ScaleWidth,0,
WINDOW_ScaleHeight,0,
WINDOW_SizeGadget,FALSE,
WINDOW_AppWindow,TRUE,
WINDOW_CloseOnEsc,TRUE,
WINDOW_MenuStrip,
[
1,0,'Project',NIL,0,0,0,
2,0,'About...','A',0,0,ID_ABOUT,
2,0,-1,0,0,0,0,
2,0,'Select icon...','O',0,0,ID_SELECT,
2,0,-1,0,0,0,0,
2,0,'Quit','Q',0,0,ID_QUIT,
1,0,'Options',NIL,0,0,0,
2,0,'Copy image','I',CHECKIT OR MENUTOGGLE,0,ID_CIMAGE,
2,0,'Copy type and default tool','T',CHECKIT OR MENUTOGGLE,0,ID_CTYPE,
2,0,'Copy tool types','L',CHECKIT OR MENUTOGGLE,0,ID_CTTYPES,
0,0,NIL,0,0,0]:newmenu,
WINDOW_MasterGroup,
HGroupObject,Spacing(4),HOffset(4),VOffset(4),GROUP_EqualWidth,doeqw,
StartMember,g_Src:=ButtonObject,
FRM_Type,FRTYPE_DROPBOX,
FRM_Recessed,FALSE,
LAB_Label,'_Source',
LAB_Place,PLACE_ABOVE,
GA_ID,ID_SRC,
BUTTON_Image,[0,0,maxw,maxh,0,NIL,0,0,NIL]:image,
EndObject,EndMember,
StartMember,g_Dest:=InfoObject,
FRM_Type,FRTYPE_DROPBOX,
FRM_Recessed,FALSE,
LAB_Label,'Destination',
LAB_Place,PLACE_ABOVE,
EndObject,EndMember,
EndObject,EndMember,
EndObject
IF wd_obj=NIL THEN Raise(ERR_GUI)
IF copy AND CP_IMAGE THEN domethod(wd_obj,[WM_CHECKITEM,ID_CIMAGE,TRUE])
IF copy AND CP_TYPE THEN domethod(wd_obj,[WM_CHECKITEM,ID_CTYPE,TRUE])
IF copy AND CP_TTYPES THEN domethod(wd_obj,[WM_CHECKITEM,ID_CTTYPES,TRUE])
GadgetKey(wd_obj,g_Src,'s')
wnd:=WindowOpen(wd_obj)
IF wnd=NIL THEN Raise(ERR_WIN)
GetAttr(WINDOW_SigMask,wd_obj,{sig})
GetAttr(WINDOW_AppMask,wd_obj,{i})
sig:=sig OR i
done:=FALSE
WHILE done=FALSE
Wait(sig)
WHILE (rc:=HandleEvent(wd_obj))<>WMHI_NOMORE
SELECT rc
CASE WMHI_CLOSEWINDOW; done:=TRUE
CASE ID_ABOUT; about()
CASE ID_SELECT; selecticon(name)
CASE ID_QUIT; done:=TRUE
CASE ID_CIMAGE
IF domethod(wd_obj,[WM_ITEMCHECKED,rc]) THEN copy:=copy OR CP_IMAGE ELSE copy:=copy AND Not(CP_IMAGE)
CASE ID_CTYPE
IF domethod(wd_obj,[WM_ITEMCHECKED,rc]) THEN copy:=copy OR CP_TYPE ELSE copy:=copy AND Not(CP_TYPE)
CASE ID_CTTYPES
IF domethod(wd_obj,[WM_ITEMCHECKED,rc]) THEN copy:=copy OR CP_TTYPES ELSE copy:=copy AND Not(CP_TTYPES)
ENDSELECT
ENDWHILE
WHILE amsg:=GetAppMsg(wd_obj)
rc:=NIL
IF amsg.numargs THEN rc:=domethod(wd_obj,[WM_WHICHOBJECT])
IF rc=g_Src
IF diskobj_src THEN FreeDiskObject(diskobj_src)
diskobj_src:=NIL
wa:=amsg.arglist[0]
diskobj_src:=getdiskobj(wa,name)
setsource()
ELSEIF rc=g_Dest
IF diskobj_src<>NIL AND copy
IF diskobj_dst THEN FreeDiskObject(diskobj_dst)
diskobj_dst:=NIL
FOR i:=0 TO amsg.numargs-1
IF diskobj_dst:=getdiskobj(amsg.arglist[i],name)
CopyMem(diskobj_dst.gadget,oldgadget,SIZEOF gadget)
IF copy AND CP_IMAGE
CopyMem(diskobj_src.gadget,diskobj_dst.gadget,SIZEOF gadget)
ENDIF
olddeft:=diskobj_dst.defaulttool
IF copy AND CP_TYPE AND (diskobj_dst.type=WBTOOL OR (diskobj_dst.type=WBPROJECT))
diskobj_dst.type:=diskobj_src.type
diskobj_dst.defaulttool:=diskobj_src.defaulttool
ENDIF
oldtt:=diskobj_dst.tooltypes
IF copy AND CP_TTYPES
diskobj_dst.tooltypes:=diskobj_src.tooltypes
ENDIF
cd:=CurrentDir(amsg.arglist[i].lock)
IF PutDiskObject(name,diskobj_dst)=0
-> avoid Skip/Abort choice when it doesn't matter
IF bguireq(NIL,'Unable to write back icon.',
IF i=(amsg.numargs-1) THEN '*_OK' ELSE '*_Skip|_Abort')=
0 THEN i:=amsg.numargs
ENDIF
CurrentDir(cd)
CopyMem(oldgadget,diskobj_dst.gadget,SIZEOF gadget)
diskobj_dst.defaulttool:=olddeft
diskobj_dst.tooltypes:=oldtt
FreeDiskObject(diskobj_dst); diskobj_dst:=NIL
ELSE
IF bguireq(NIL,'Can''t get icon!',
IF i=(amsg.numargs-1) THEN '*_OK' ELSE '*_Skip|_Abort')=
0 THEN i:=amsg.numargs -> can't use EXIT inside IF
ENDIF
ENDFOR
ELSE
DisplayBeep(0)
ENDIF
ELSE
DisplayBeep(0)
ENDIF
ReplyMsg(amsg)
ENDWHILE
ENDWHILE
EXCEPT DO
IF wd_obj THEN DisposeObject(wd_obj)
IF filereq THEN DisposeObject(filereq)
IF bguibase THEN CloseLibrary(bguibase)
IF diskobj_dst THEN FreeDiskObject(diskobj_dst)
IF diskobj_src THEN FreeDiskObject(diskobj_src)
IF iconbase THEN CloseLibrary(iconbase)
SELECT exception
CASE ERR_LIB; WriteF('Error: could not open icon or BGUI library.\n')
CASE ERR_GUI; WriteF('Error: could not create GUI object.\n')
CASE ERR_WIN; WriteF('Error: could not open window.\n')
ENDSELECT
ENDPROC
PROC getdiskobj(wa:PTR TO wbarg,name:PTR TO CHAR)
DEF do=NIL:PTR TO diskobject,cd
StrCopy(name,wa.name)
IF name[]
cd:=CurrentDir(wa.lock)
do:=GetDiskObjectNew(name)
CurrentDir(cd)
ELSE -> drawer, garbage or disk
IF NameFromLock(wa.lock,name,StrMax(name))
SetStr(name,StrLen(name))
IF name[EstrLen(name)-1]=":" THEN StrAdd(name,'disk')
do:=GetDiskObjectNew(name)
ENDIF
ENDIF
ENDPROC do
PROC gettooltypes(tempstr:PTR TO CHAR /* stratch EString */)
DEF wb:PTR TO wbstartup,cd
IF wb:=wbmessage
cd:=CurrentDir(wb.arglist[0].lock)
readtt(wb.arglist[0].name)
CurrentDir(cd)
ELSE
GetProgramName(tempstr,StrMax(tempstr))
cd:=CurrentDir(GetProgramDir())
readtt(FilePart(tempstr))
CurrentDir(cd)
ENDIF
ENDPROC
PROC readtt(name:PTR TO CHAR)
DEF s,do:PTR TO diskobject,tt:PTR TO LONG
IF (do:=GetDiskObject(name))=NIL THEN RETURN
tt:=do.tooltypes
IF s:=FindToolType(tt,'EQUALWIDTH')
doeqw:=TRUE
IF s[]="n" OR (s[]="N") THEN doeqw:=FALSE
ENDIF
IF s:=FindToolType(tt,'MAXWIDTH')
maxw:=Max(Val(s),5)
ENDIF
IF s:=FindToolType(tt,'MAXHEIGHT')
maxh:=Max(Val(s),5)
ENDIF
IF s:=FindToolType(tt,'COPYIMAGE')
copy:=copy OR CP_IMAGE
IF s[]="n" OR (s[]="N") THEN copy:=copy AND Not(CP_IMAGE)
ENDIF
IF s:=FindToolType(tt,'COPYTYPE')
copy:=copy OR CP_TYPE
IF s[]="n" OR (s[]="N") THEN copy:=copy AND Not(CP_TYPE)
ENDIF
IF s:=FindToolType(tt,'COPYTOOLTYPES')
copy:=copy OR CP_TTYPES
IF s[]="n" OR (s[]="N") THEN copy:=copy AND Not(CP_TTYPES)
ENDIF
IF s:=FindToolType(tt,'DEFDRAWER')
StrCopy(defdrawer,s)
ENDIF
FreeDiskObject(do)
ENDPROC
PROC about()
bguireq('About WReplaceIcon',
'\ec\s\n'+
'Freeware\n'+
'Copyright © 1999 Jilles Tjoelker\n\n'+
'\ebE-mail:\n\enM.Tjoelker@nl.cis.philips.com\n\n'+
'\ebSnail mail:\en\nJilles Tjoelker\n'+
'Craterlaan 6\n'+
'5632 AG Eindhoven\n'+
'THE NETHERLANDS','*_OK',[{verstag}+6])
ENDPROC
PROC selecticon(name:PTR TO CHAR /* stratch EString */)
DEF drw,file,path
IF filereq=NIL
filereq:=FileReqObject,
ASLFR_INITIALPATTERN,'#?.info',
ASLFR_TITLETEXT,'Select icon',
ASLFR_POSITIVETEXT,'Load',
ASLFR_INITIALDRAWER,defdrawer,
EndObject
IF filereq=NIL THEN RETURN DisplayBeep(NIL)
ENDIF
IF DoRequest(filereq)=ASLREQ_OK
IF diskobj_src THEN FreeDiskObject(diskobj_src)
diskobj_src:=NIL
GetAttr(FILEREQ_Drawer,filereq,{drw})
GetAttr(FILEREQ_File,filereq,{file})
GetAttr(FILEREQ_Path,filereq,{path})
IF file[]=0
StrCopy(name,drw)
IF name[StrLen(name)-1]=":" THEN StrAdd(name,'disk')
diskobj_src:=GetDiskObjectNew(name)
ELSE
StrCopy(name,path)
IF diskobj_src=NIL AND (EstrLen(name)>5)
IF StrCmp(name+EstrLen(name)-5,'.info')
SetStr(name,EstrLen(name)-5) -> strip .info
ENDIF
ENDIF
diskobj_src:=GetDiskObjectNew(name)
ENDIF
setsource()
ENDIF
ENDPROC
PROC setsource()
DEF img:PTR TO image
IF diskobj_src
img:=diskobj_src.gadget.gadgetrender
IF img.width>maxw OR (img.height>maxh) THEN img:=NIL
SetGadgetAttrsA(g_Src,wnd,NIL,[BUTTON_Image,img,0])
IF diskobj_src.gadget.selectrender
img:=diskobj_src.gadget.selectrender
IF img.width>maxw OR (img.height>maxh) THEN img:=NIL
SetGadgetAttrsA(g_Src,wnd,NIL,[BUTTON_SelectedImage,img,0])
ELSE
SetGadgetAttrsA(g_Src,wnd,NIL,[BUTTON_SelectedImage,img,0])
ENDIF
ELSE
SetGadgetAttrsA(g_Src,wnd,NIL,[BUTTON_Image,NIL,BUTTON_SelectedImage,NIL,0])
bguireq(NIL,'Can''t get source icon!','*_OK')
ENDIF
ENDPROC